package chapter06;
import java.util.HashSet;
import java.util.Scanner;
public class Test06_Fruit {
    public static void main(String[] args) {
        while(true){
            System.out.println("请输入要执行的操作：");
            System.out.println("1、增加水果");
            System.out.println("2、删除水果");
            System.out.println("3、查找水果");
            System.out.println("4、输出水果");
            System.out.println("5、退出水果篮子");
            Scanner scanner = new Scanner(System.in);
            int op = scanner.nextInt();
            if(op==1){
                System.out.println("请输入水果：");
                String e = scanner.next();
                Test06_Fruit.addFruit(e);
                System.out.println("请按任意键继续...");
                scanner.next();
            }else if(op==2){
                System.out.println("请输入要删除的水果：");
                String e = scanner.next();
                Test06_Fruit.deleteFruit(e);
                System.out.println("请按任意键继续...");
                scanner.next();
            } else if (op==3) {
                System.out.println("请输入要查找的水果：");
                String e = scanner.next();
                Test06_Fruit.checkFruit(e);
                System.out.println("请按任意键继续...");
                scanner.nextLine();
            } else if (op==4) {
                System.out.println("水果篮子里的水果有：");
                Test06_Fruit.printFruit();
                System.out.println("请按任意键继续...");
                scanner.next();
            }else if(op==5){
                System.out.println("退出系统");
                break;
            }else{
                System.out.println("输入的操作码有误，请重新输入");
                System.out.println("请按任意键继续...");
                scanner.next();
            }
        }
    }
    private static HashSet t = new HashSet<>();
    //增加水果
    public static void addFruit(String e){
        t.add(e);
        System.out.println("增加"+e+"成功");
    }
    //删除水果
    public static void deleteFruit(String e){
        if(t.contains(e)){
            t.remove(e);
            System.out.println("删除"+e+"成功");
        }else{
            System.out.println("该水果不存在");
        }
    }
    //查找水果
    public static void checkFruit(String e){
        if(t.contains(e)){
            System.out.println(e+"水果存在");
        }else{
            System.out.println(e+"水果不存在");
        }
    }
    //所有水果输出
    public static void printFruit(){
        for(Object f:t){
            System.out.println(f);
        }
    }
}
